-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(MessageEmbed): Skip validation of field when inside a message #3894
fix(MessageEmbed): Skip validation of field when inside a message #3894
Conversation
Been running this fork on my bot that originally found this issue for a while now, hasn't thrown this error so I'm pretty confident this flag is working as intended. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing something like [{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }]
to addFields
or spliceFields
on embeds skipping validation breaks the fields
property:
// Assume this embed is taken from `Message#embeds` rather than being manually instantiated.
> new MessageEmbed({}, true).addFields([{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }]).fields
[
Array {
'0': { name: 'foo', value: 'bar' },
'1': { name: 'foo', value: 'bar' }
}
]
Compared to:
> new MessageEmbed({}).addFields([{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }]).fields
[
{ name: 'foo', value: 'bar', inline: false },
{ name: 'foo', value: 'bar', inline: false }
]
The fix is to Array#flat
the fields, like normalizeFields
does too.
While modifying those embeds is not exactly a recommended use-case, it is a "supported" one and shouldn't break.
- dead code discord.js does not use those methods interally and won't in the future, as Discord does not emit any partial embed updates and doing so in the future seems unlikely. - a breaking change (an incompatible api change) Although it's not recommended to do, users can modify received embeds without cloning them, e.g.: const embed = message.embeds[0].addField('some title', ''); (replace '' with some function call; this is just an example) This would no longer throw a synchronous error (breaking change), but at a later point when actually sending it. (poorer to debug)
Please describe the changes this PR makes and why it should be merged:
This should fix #3892 by skipping validation on embeds when they are part of a parent message.
The library works fine with this change, but per discussion in #library-discussion, we can't actually reproduce the buggy embed to test this. One should be able to assume this will work though (assuming I've added the flag in the right places) as it is disabling the validation that was throwing the error.
Status
Semantic versioning classification: